package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: SetmealController
 * Package: com.sky.controller.admin
 * Description:
 *
 * @Author Dylan_Jun
 * @Create 2024/2/1 13:45
 * @Version 1.0
 */
@Slf4j
@Api(tags = "套餐相关接口")
@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @ApiOperation("新增套餐")
    @CacheEvict(cacheNames = "setmealCache", key = "#dto.categoryId")
    @PostMapping
    public Result save(@RequestBody SetmealDTO dto){
        log.info("新增套餐");
        setmealService.save(dto);
        return Result.success();
    }

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("分页查询,{}", setmealPageQueryDTO);
        PageResult res = setmealService.pageQuery(setmealPageQueryDTO);
        return Result.success(res);
    }

    @ApiOperation("批量删除套餐")
    @DeleteMapping
    @CacheEvict(cacheNames = "setmealCache", allEntries = true)
    public Result deleteBatch(@RequestParam List<Long> ids){
        log.info("批量删除套餐, {}", ids);
        setmealService.deleteBatch(ids);
        return Result.success();
    }

    @ApiOperation("根据id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id){
        log.info("根据id查询套餐,{}", id);
        SetmealVO vo = setmealService.getById(id);
        return Result.success(vo);
    }

    @ApiOperation("修改套餐")
    @PutMapping
    @CacheEvict(cacheNames = "setmealCache", allEntries = true)
    public Result update(@RequestBody SetmealDTO dto){
        log.info("修改套餐,{}", dto);
        setmealService.update(dto);
        return Result.success();
    }

    @ApiOperation("套餐状态设置")
    @PostMapping("/status/{status}")
    @CacheEvict(cacheNames = "setmealCache", allEntries = true)
    public Result setStatus(@PathVariable Integer status, Long id){
        log.info("菜品状态设置,{},{}", status, id);
        setmealService.setStatus(status, id);
        return Result.success();
    }
}
